package Demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-06-15
 * Time: 15:09
 */
public class Test {
    public static void main(String[] args) {

    }
    public static void main5(String[] args) {//字符串切割
        String str = "    3425588767@qq.com    ";
        String[] ret = str.split(" ");
        for (String s:ret) {
            System.out.println(s);
        }
        ret = str.split(" ",2);
        for (String s:ret) {
            System.out.println(s);
        }
        ret = str.split("8|@");
        for (String s:ret) {
            System.out.println(s);
        }
        System.out.println(str.trim());
    }
    public static void main4(String[] args) {//字符串替换
        String str = "hello world";
        System.out.println(str.replace("l", "2"));
        System.out.println(str.replace("he", "lllll"));
        System.out.println(str.replace("h", "jj"));
        System.out.println(str.replaceAll("he", "jj"));
        System.out.println(str.replaceFirst("l", "hhhh"));
    }
    public static void main3(String[] args) {//字符串截取
        String str = "hello world";
        System.out.println(str.substring(6));
        System.out.println(str.substring(1, 5));
    }
    public static void main2(String[] args) {//字符串查找
        String str = "hello world";
        int ret = str.indexOf('h');
        System.out.println(ret);
        for (int i = 0; i < str.length(); i++) {
            System.out.print(str.charAt(i));
        }
        ret = str.indexOf('3',1);
        System.out.println(ret);
        System.out.println(str.indexOf("world",7));
        System.out.println(str.lastIndexOf("hello"));
    }
    public static void main1(String[] args) {
        //字符串三种构造方式
        //常量字符串赋值
        String str1 = "hello world";
        //调用构造方法构造
        String str2 = new String("abc");
        //使用字符数组构造
        char[] str = new char[]{'d','e','f'};
        String str3 = new String(str);

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}
